<template>
  <div class="modal" :id="id" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title">
            <slot name="title"> 批量创建结算单 </slot>
          </h5>
          <button
            type="button"
            class="btn-close"
            data-bs-dismiss="modal"
            aria-label="Close"
          ></button>
        </div>
        <div class="modal-body">
          <form role="form" class="form-horizontal">
            <div class="row mb-1">
              <label class="col-3 col-form-label">客户</label>
              <div class="col-9">
                <my-select-customer
                  :status="1"
                  :customerId.sync="customerId"
                ></my-select-customer>
              </div>
            </div>

            <div class="row mb-1">
              <label class="col-3 col-form-label">开始日期</label>
              <div class="col-9">
                <my-date-picker
                  id="dateRangeBegin"
                  v-model.trim="beginDate"
                ></my-date-picker>
              </div>
            </div>
            <div class="row mb-1">
              <label class="col-3 col-form-label">截止日期</label>
              <div class="col-9">
                <my-date-picker
                  id="dateRangeEnd"
                  v-model.trim="endDate"
                ></my-date-picker>
              </div>
            </div>
            <div class="row mb-1">
              <label class="col-3 col-form-label">结算单号前缀</label>
              <div class="col-9">
                <input class="form-control" v-model.trim="prefix" />
                <span class="text-muted small"
                  >结算单号由前缀+企业名组成，此处为空则系统自动生成前缀</span
                >
              </div>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-secondary me-2"
            data-bs-dismiss="modal"
          >
            关闭
          </button>
          <button type="button" class="btn btn-primary" @click.stop="ok()">
            确定
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import $ from "jquery";
import MyDatePicker from "@/components/my-datepicker.vue";
import MySelectCustomer from "@/components/my-select-customer.vue";

export default {
  props: {
    id: {
      type: String,
      default: "modalPrompt",
    },
  },
  components: {
    MyDatePicker,
    MySelectCustomer,
  },
  data() {
    return {
      resolve: "",
      reject: "",
      promise: "",

      beginDate: "",
      endDate: "",
      customerId: -1,
      prefix: "",

      myModal: null
    };
  },
  methods: {
    ok: function () {
     this.hideModal();
      this.resolve({
        beginDate: this.beginDate,
        endDate: this.endDate,
        customerId: this.customerId,
        prefix: this.prefix,
      });
    },
    modal: function (val) {
      this.showModal();

      this.promise = new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
      return this.promise;
    },
    showModal: function () {
      this.getMyModal().show();
    },
    hideModal: function () {
      this.getMyModal().hide();
    },
    getMyModal: function () {
      if (this.myModal === null) {
        let myModalEl = $(this.$el).get(0);
        this.myModal = new bootstrap.Modal(myModalEl, {
          keyboard: true,
        });
      }

      return this.myModal;
    },
  },
};
</script>
